package com.newasia.server.common.proxy;

import com.newasia.server.common.dataSource.DynamicDataSourceContextHolder;
import com.newasia.server.common.strategy.dataConversion.DataConversionStrategy;
import com.newasia.server.dal.entitys.BaseData;
import com.newasia.server.dal.entitys.MonitorDetail;
import com.newasia.server.dal.entitys.returnValue.MonitorState;
import com.newasia.server.service.IHistoryService;
import com.newasia.server.service.IMonitorDetailService;
import com.newasia.server.service.IMonitorDetailBakService;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LiChong
 * @description 用于监控点信息的数据解析
 * @date 2020/4/10
 */

@Slf4j
public class DataConversionProxy implements InvocationHandler {

    private Object proxyObj;
    public Object getInstance(Class clazz) {
        try{
            //反射需要实例化调用对象
            this.proxyObj = Class.forName(clazz.getName()).newInstance();
        }catch (Exception e){
            log.error("MonitorProxy.getInstance:"+e);
            e.printStackTrace();
        }
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return DataConversionStrategy.get(proxyObj,method,args);
    }
}
